package cn.wolfcode.shop.cloud.mq;

import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.Map;
@RocketMQMessageListener(
        consumerGroup = MQConstans.CREATE_ORDER_SUCCESS_GROUP,
        topic = MQConstans.CREATE_ORDER,
        selectorExpression = MQConstans.CREATE_ORDER_SUCCESS_TAG
)
@Component
public class OrderSuccessMQListener implements RocketMQListener<Map> {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Override
    public void onMessage(Map map) {
        System.out.println("发送延时消息");
        //成功后要发送延时消息
        Message<Map> build = MessageBuilder.withPayload(map).build();
        rocketMQTemplate.syncSend(MQConstans.CREATE_ORDER_DELAY_DEST,build,3000,16);

    }
}
